package com.ruiyi.adrobot.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
    private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static String getCurrentTime() {
        return sdf.format(new Date());
    }

    public static long getTimeByString(String timeStr) {
        try {
            Date date = sdf.parse(timeStr);
            return date.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
            return 0;
        }
    }

    public static String getDateStringByTime(long time) {

        return sdf.format(new Date(time));
    }

    public static String addDate(String timeStr, int i) {
        if (i >= 0) {
            long time = getTimeByString(timeStr) + 86400000 * i;
            return sdf.format(new Date(time));
        } else {
            return timeStr;
        }
    }

    public static Object getCurrentTimeStart() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(new Date()) + " 00:00:00";
    }

    public static Object getCurrentTimeEnd() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(new Date()) + " 23:59:59";
    }
}
